/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Matrimonial;

import Login.MySqlConnector;
import java.sql.*;
import java.util.ArrayList;
/**
  *
  * @author Bharath
  */
public class ViewMatMemberDao {

    Connection con;
    PreparedStatement ps;
    ResultSet rs;
    MySqlConnector ms = new MySqlConnector();
    MarRegisterBean rbean = new MarRegisterBean();
    private String q;
    private ArrayList al;
 
    
    public MarRegisterBean view_member(String rcheck)
    {
        try {
            con = ms.Connect();
            String sql = " select * from mar_reg where memid = '" + rcheck + "'; ";
            System.out.println("Query in view_member() method is "+sql);
            ps = con.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next() == true)
            {
            System.out.println("get value of member is ");
            rbean.setMemid(rs.getString(2));
            rbean.setMatchfor(rs.getString(3));
            rbean.setMname(rs.getString(4));
            rbean.setMsname(rs.getString(5));
            rbean.setMgen(rs.getString(6));
            rbean.setMdob(rs.getString(7));
            rbean.setMstat(rs.getString(9));
            rbean.setMage(rs.getString(8));
            rbean.setMht(rs.getString(10));
            rbean.setReligion(rs.getString(11));
            rbean.setMcaste(rs.getString(12));
            rbean.setMlang(rs.getString(13));
            rbean.setBtype(rs.getString(14));
            rbean.setComplex(rs.getString(15));
            rbean.setSelf_desc(rs.getString(16));
            rbean.setMadd(rs.getString(17));
            rbean.setMcountry(rs.getString(18));
            rbean.setMstate(rs.getString(19));
            rbean.setMdist(rs.getString(20));
            rbean.setMcity(rs.getString(21));
            rbean.setMorg(rs.getString(22));
            rbean.setMqual(rs.getString(23));
            rbean.setMprof(rs.getString(24));
            rbean.setMemail(rs.getString(25));
            rbean.setMmob(rs.getString(26));
            rbean.setMsal(rs.getString(27));
            rbean.setRegdate(rs.getString(28));
            return rbean;
            }
                     
        }   catch (Exception e) {
            e.printStackTrace();
        }
      return null;
    }
public boolean Delete_Member(String rcheck) throws Exception
    {
    System.out.println("In delete member method ");
    System.out.println("rcheck value in delete member is "+rcheck);
    try {
            con = ms.Connect();
            q = "delete from mar_req where memberid = '"+rcheck+"' ;";
            ps = con.prepareStatement(q);
            int i= ps.executeUpdate();
            if (i == 1)
            {
                System.out.print("in If i ==1 condition delete member method");
                return true;
            }
            else
                return false;
        } catch (SQLException ex) {
          ex.printStackTrace();
        }
    return false ;
    }

    public ArrayList Mat_Search(String gender, String age, String qual) {
        try{
            con = ms.Connect();
            q = "SELECT memberid , name , surname , matchfor , mname , msname , mage , mobile , mqual, mprof " +
                    "FROM registration, mar_reg where registration.memberid = mar_reg.memid " +
                    "and mqual = '"+qual+"' and mage >= "+age+" and mgen = '"+gender+"';";
            ps = con.prepareStatement(q);
            rs = ps.executeQuery();
            System.out.println("Query is +++++"+ps);
            if(rs.next()==true)
            {
                System.out.println("in rs .next condition"   );
                al.add(rs.getString(1));
                al.add(rs.getString(2));
                al.add(rs.getString(3));
                al.add(rs.getString(4));
                al.add(rs.getString(5));
                al.add(rs.getString(6));
                al.add(rs.getString(7));
                al.add(rs.getString(8));
                al.add(rs.getString(9));
                al.add(rs.getString(10));
              System.out.println("array list "+al);

            if (al.size()!= 0)
            {
            return al;
            }
            }
        }catch(Exception ex){ex.printStackTrace();}
        
        return null;
    }

    
}
